package me.zhengjie.minbearwcs.dao.outbound.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import lombok.RequiredArgsConstructor;
import me.zhengjie.minbearwcs.dao.outbound.inf.OutboundOrderDetailDao;
import me.zhengjie.minbearwcs.entity.Mapper.outbound.OutboundOrderDetailMapper;
import me.zhengjie.minbearwcs.entity.PO.wcs.outbound.OutboundOrderDetail;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@RequiredArgsConstructor
public class OutboundOrderDetailDaoImpl implements OutboundOrderDetailDao {

    private final OutboundOrderDetailMapper mapper;

    @Override
    public boolean insert(OutboundOrderDetail outboundOrderDetail) {
        return mapper.insert(outboundOrderDetail) == 1;
    }

    @Override
    public boolean updateStockUpNumById(Integer id, Integer stockUpNum) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(OutboundOrderDetail::getId,id)
                .set(OutboundOrderDetail::getStockUpNum,stockUpNum)
                .update();
    }

    @Override
    public OutboundOrderDetail selectByDetailId(String detailId) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(OutboundOrderDetail::getOutboundDetailId,detailId)
                .one();
    }

    @Override
    public List<OutboundOrderDetail> selectByOutboundOrderCode(String OutboundOrderCode) {
        return new LambdaQueryChainWrapper<>(mapper)
                .eq(OutboundOrderDetail::getOutboundOrderCode,OutboundOrderCode)
                .list();
    }

    @Override
    public boolean updateCompleteNumById(Integer id, Integer completeNum) {
        return new LambdaUpdateChainWrapper<>(mapper)
                .eq(OutboundOrderDetail::getId,id)
                .set(OutboundOrderDetail::getCompleteNum,completeNum)
                .update();
    }

    @Override
    public boolean deleteById(Integer id) {
        return mapper.deleteById(id) == 1;
    }


}
